Skip to content

feat(snackbar): Auto Hide for Snackbar #1641

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed

feat(snackbar): Auto Hide for Snackbar #1641

wants to merge 5 commits into from

Conversation

kvcpr
Copy link

@kvcpr kvcpr commented Oct 28, 2016

I have created auto hide for snackbar.
autoHideDuration: number | boolean - The number of milliseconds to wait before automatically dismissing. If no value is specified the snackbar will dismiss normally.

  • Added autoHideDuration option to MdSnackBarConfig
  • Snackbar hide after autoHideDuration If no value is specified the snackbar will dismiss normally.
  • If a snackbar is dismissed before the timer expires, the timer will be cleared.

r: @josephperrott

@googlebot
Copy link

Thanks for your pull request. It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

📝 Please visit https://cla.developers.google.com/ to sign.

Once you've signed, please reply here (e.g. I signed it!) and we'll verify. Thanks.


  • If you've already signed a CLA, it's possible we don't have your GitHub username or you're using a different email address. Check your existing CLA data and verify that your email is set on your git commits.
  • If you signed the CLA as a corporation, please let us know the company's name.

@googlebot googlebot added the cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla label Oct 28, 2016
@googlebot
Copy link

CLAs look good, thanks!

@googlebot googlebot added cla: yes PR author has agreed to Google's Contributor License Agreement and removed cla: no PR author must sign Google's Contributor License Agreement: https://opensource.google.com/docs/cla labels Oct 28, 2016
@kvcpr
Copy link
Author

kvcpr commented Oct 28, 2016

I signed it!

@kvcpr kvcpr changed the title Auto Hide for Snackbar feat(snackbar): Auto Hide for Snackbar Oct 29, 2016
@kvcpr kvcpr changed the title feat(snackbar): Auto Hide for Snackbar feat(snackbar): Auto Hide for Snackbar [pr: needreview] Oct 29, 2016
@kvcpr kvcpr changed the title feat(snackbar): Auto Hide for Snackbar [pr: needreview] feat(snackbar): Auto Hide for Snackbar [pr: needs review] Oct 29, 2016
@kvcpr kvcpr changed the title feat(snackbar): Auto Hide for Snackbar [pr: needs review] feat(snackbar): Auto Hide for Snackbar Nov 8, 2016
Copy link
Member

@jelbourn jelbourn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change also needs unit tests.

*/
autoHideDuration: number | boolean;

constructor(viewContainerRef: ViewContainerRef, autoHideDuration: number | boolean = false) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Rather than being a constructor argument, this should just be a property that is set to the config with a default. We will shortly be giving the snackbar config the same treatment as the dialog config (#1679).

* If a value is provided the snackbar can still be dismissed normally.
* If a snackbar is dismissed before the timer expires, the timer will be cleared.
*/
autoHideDuration: number | boolean;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would just call this duration, where the value is null if it is persistent.

@@ -19,6 +19,8 @@ export class MdSnackBarRef<T> {
/** Subject for notifying the user that the snack bar has closed. */
private _afterClosed: Subject<any> = new Subject();

autoHide: number;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

_autoDismissTimeoutId

@@ -36,6 +38,10 @@ export class MdSnackBarRef<T> {
this._afterClosed.complete();
});
}
// Clear autohide interval
if (this.autoHide) {
clearInterval(this.autoHide);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you use setTimeout, the corresponding cancel function is cancelTimeout

@@ -56,6 +54,12 @@ export class MdSnackBar {
} else {
mdSnackBarRef.containerInstance.enter();
}
// Auto dismiss after timeout.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment like

// If the snackbar has a specified duration, set up a timeout to automatically dismiss it.

@@ -56,6 +54,12 @@ export class MdSnackBar {
} else {
mdSnackBarRef.containerInstance.enter();
}
// Auto dismiss after timeout.
if (config.autoHideDuration) {
mdSnackBarRef.autoHide = setTimeout(() => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You don't need the braces:

mdSnackBarRef._autoDismissTimeoutId = 
    setTimeout(() => mdSnackBarRef.dismiss(), config.duration);

@jelbourn
Copy link
Member

Closing in favor of #1856

@jelbourn jelbourn closed this Nov 14, 2016
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 6, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
cla: yes PR author has agreed to Google's Contributor License Agreement
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants